package com.keenote.ly;

import com.keenote.file.FileUtils;
import com.keenote.http.HttpUtils;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 根据应用UK查询应用信息
 *
 * @author mic.zhou
 * @date 2022/8/17 10:34
 */
public class UkInfo {
    public static final String URL_FORMAT = "http://dev.17usoft.com/api/cmdb/app/appUk?appUk=%s";

    public static void main(String[] args) {
        List<String> uks = FileUtils.readAsStringLine(UkInfo.class.getClassLoader().getResource("uks").getFile());
        List<Info> infos = uks.stream().filter(StringUtils::isNotBlank).map(UkInfo::getUkInfoByUk).collect(Collectors.toList());
        List<String> result = new ArrayList<>();
        result.add("应用\tUK\t负责人");
        for (Info info : infos) {
            Info.AplDataDTO aplData = info.getAplData();
            result.add(String.format("%s\t%s\t%s", aplData.getCnName(), aplData.getUk(), aplData.getMaintenanceName()));
        }
        result.stream().forEach(System.out::println);
    }

    private static Info getUkInfoByUk(String uk) {
        return HttpUtils.get(String.format(URL_FORMAT, uk), Info.class);
    }

    @NoArgsConstructor
    @Data
    public static class Info {

        /**
         * status
         */
        private Integer status;
        /**
         * message
         */
        private String message;
        /**
         * aplData
         */
        private AplDataDTO aplData;
        /**
         * code
         */
        private Object code;

        /**
         * AplDataDTO
         */
        @NoArgsConstructor
        @Data
        public static class AplDataDTO {
            /**
             * id
             */
            private Integer id;
            /**
             * createdBy
             */
            private String createdBy;
            /**
             * createdDate
             */
            private String createdDate;
            /**
             * lastModifiedBy
             */
            private String lastModifiedBy;
            /**
             * lastModifiedDate
             */
            private String lastModifiedDate;
            /**
             * productLineId
             */
            private Integer productLineId;
            /**
             * appProperty
             */
            private Object appProperty;
            /**
             * productId
             */
            private Integer productId;
            /**
             * productName
             */
            private String productName;
            /**
             * productLineName
             */
            private String productLineName;
            /**
             * name
             */
            private String name;
            /**
             * cnName
             */
            private String cnName;
            /**
             * uk
             */
            private String uk;
            /**
             * maintenance
             */
            private String maintenance;
            /**
             * manager
             */
            private String manager;
            /**
             * maintenanceName
             */
            private String maintenanceName;
            /**
             * opsMaintenance
             */
            private String opsMaintenance;
            /**
             * opsMaintenanceName
             */
            private String opsMaintenanceName;
            /**
             * developer
             */
            private String developer;
            /**
             * developerName
             */
            private String developerName;
            /**
             * pd
             */
            private String pd;
            /**
             * pdName
             */
            private String pdName;
            /**
             * dba
             */
            private String dba;
            /**
             * dbaName
             */
            private String dbaName;
            /**
             * qa
             */
            private String qa;
            /**
             * qaName
             */
            private String qaName;
            /**
             * appType
             */
            private String appType;
            /**
             * deployType
             */
            private String deployType;
            /**
             * deployOs
             */
            private String deployOs;
            /**
             * status
             */
            private String status;
            /**
             * codeRepository
             */
            private String codeRepository;
            /**
             * deployVersion
             */
            private String deployVersion;
            /**
             * availability
             */
            private Integer availability;
            /**
             * domainName
             */
            private String domainName;
            /**
             * dsfName
             */
            private String dsfName;
            /**
             * isRealApplication
             */
            private Boolean isRealApplication;
            /**
             * description
             */
            private String description;
            /**
             * level
             */
            private String level;
            /**
             * groupsCount
             */
            private Integer groupsCount;
            /**
             * labels
             */
            private Object labels;
        }
    }
}
